using System.Collections;
using EnvDTE;
using NUnit.Framework;
using NUnit.Mocks;
using NUnitGenAddIn.Core.Test;

namespace NUnitGenAddIn.VS2008.Test
{
    [TestFixture]
    public class TestVS2005AddInHelper
    {
        private VS2008AddInHelper _unitUnderTest;
        private MockDTE _dte;

        [SetUp]
        public void SetUp()
        {
            _dte = new MockDTE();
            _unitUnderTest = new VS2008AddInHelper(_dte, (AddIn) new DynamicMock(typeof (AddIn)).MockInstance);
        }

        [TearDown]
        public void TearDown()
        {
            _dte = null;
            _unitUnderTest = null;
        }

        [Test]
        public void TestGetCodeClassFromCodeElements()
        {
            ArrayList memberList = new ArrayList();
            memberList.Add(new MockCodeFunction("testFunction"));

            ArrayList classList = new ArrayList();
            classList.Add(new MockCodeClass2008("testClass", new MockCodeElements(memberList)));

            ArrayList namespaceList = new ArrayList();
            namespaceList.Add(new MockCodeNamespace2008("testNamespace", new MockCodeElements(classList)));

            Assert.AreEqual("testClass", _unitUnderTest.GetCodeClassFromCodeElements(new MockCodeElements(namespaceList)).Name);
        }

        [Test]
        public void TestGetCodeElementListFromPoint()
        {
            ArrayList memberList = new ArrayList();
            MockCodeFunction codeFunction = new MockCodeFunction("testFunction");
            ((MockTextPoint) codeFunction.StartPoint).Line = 20;
            memberList.Add(codeFunction);

            ArrayList classList = new ArrayList();
            MockCodeClass2008 codeClass = new MockCodeClass2008("testClass", new MockCodeElements(memberList));
            ((MockTextPoint) codeClass.StartPoint).Line = 10;
            classList.Add(codeClass);

            ArrayList namespaceList = new ArrayList();
            MockCodeNamespace2008 codeNamespace = new MockCodeNamespace2008("testNamespace", new MockCodeElements(classList));
            ((MockTextPoint) codeNamespace.StartPoint).Line = 0;
            namespaceList.Add(codeNamespace);

            MockProjectItem projectItem = new MockProjectItem();
            projectItem.SetFileCodeModel(new MockFileCodeModel2008(new MockCodeElements(namespaceList)));
            MockDocument doc = new MockDocument();
            doc.SetProjectItem(projectItem);
            _dte.SetActiveDocument(doc);
            MockTextPoint point = new MockTextPoint(0, 20);

            Assert.AreEqual(3, _unitUnderTest.GetCodeElementListFromPoint(point).Count,
                            "GetCodeElementListFromPoint returns wrong CodeElement list.");
        }

        [Test]
        public void TestAddCommandToCommandBar()
        {
            _unitUnderTest.AddCommandToCommandBar("commandName", "buttonText", "tooltip", "commandBarName");
            Assert.Fail();
        }
    }
}